package com.cadre.web.controller.officer;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.cadre.common.utils.R;
import com.cadre.common.utils.annotation.A04Tag;
import com.cadre.common.utils.annotation.SysLog;
import com.cadre.common.utils.common.GenerateUUID;
import com.cadre.common.utils.oldutil.DateUtil;
import com.cadre.common.utils.oldutil.ValidatorUtils;
import com.cadre.system.domain.officer.A01;
import com.cadre.system.domain.officer.A01Education;
import com.cadre.system.domain.officer.A04;
import com.cadre.system.domain.vo.ESUtil;
import com.cadre.system.service.A01EducationService;
import com.cadre.system.service.A01Service;
import com.cadre.system.service.A04Service;
import com.cadre.system.service.DIC_ZBService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

@Api(value = "学历Controller", tags = {"干部学历接口"})
@RequestMapping({"/profess/a04"})
@RestController
/* loaded from: A04Controller.class */
public class A04Controller {
    @Autowired
    private A04Service a04Ser;
    @Resource
    private DIC_ZBService dIC_ZBService;
    @Resource
    private A01Service a01Service;
    @Resource
    private A01EducationService a01EducationService;
    @Autowired
    RestHighLevelClient client;

    @PostMapping({"/editA04Msg/{personid}"})
    @ApiOperation("操作A04")
    public R editA04Msg(@RequestBody List<A04> list, @PathVariable("personid") String personid) throws IOException {
        List<A04> listA04ES = new ArrayList<>();
        if (list.size() > 0) {
            personid = list.get(0).getPersonid();
            this.a04Ser.deleteByFlowid((String[]) ((List) this.a04Ser.selectList(personid).stream().map(t -> {
                return t.getFlowid();
            }).collect(Collectors.toList())).toArray(new String[0]));
            for (int i = 0; i < list.size(); i++) {
                A04 a04 = list.get(i);
                a04.setFlowid(GenerateUUID.getUUID());
                this.a04Ser.insertSelectiveDate(a04);
                listA04ES.add(a04);
            }
            updateA01_3(list, personid);
            updateA01_3_Meet(list, personid);
        } else {
            this.a04Ser.deleteByFlowid((String[]) ((List) this.a04Ser.selectList(personid).stream().map(t -> {
                return t.getFlowid();
            }).collect(Collectors.toList())).toArray(new String[0]));
            saveA01Msg(personid);
            updateA01_3_Meet(list, personid);
        }
        try{
            Map<String, Object> source = this.client.get(new GetRequest(ESUtil.a01Index, personid), RequestOptions.DEFAULT).getSource();
            if (source != null) {
                A01 a01s = ESUtil.useObjectMapper(source);
                a01s.setA04List(listA04ES);
                this.client.index(new IndexRequest(ESUtil.a01Index).id(a01s.getFlowid()).source(JSON.toJSONString(a01s), XContentType.JSON), RequestOptions.DEFAULT);
            }
        }catch (Exception e){

        }
        return R.ok();
    }

    public void updateA01_3_Meet(List<A04> list, String personid) {
        if (list.size() > 0) {
            List<A04> list_qrz = new ArrayList<>();
            List<A04> list_zz = new ArrayList<>();
            boolean boo = false;
            int i = 0;
            while (true) {
                if (i >= list.size()) {
                    break;
                } else if (list.get(i).getIsoutMeet().shortValue() != 9) {
                    boo = false;
                    break;
                } else {
                    boo = true;
                    i++;
                }
            }
            if (!boo) {
                for (int i2 = 0; i2 < list.size(); i2++) {
                    if (list.get(i2).getIsoutMeet().shortValue() == 1 && list.get(i2).getA0449().equals("1")) {
                        list_qrz.add(list.get(i2));
                    } else if (list.get(i2).getIsoutMeet().shortValue() == 1 && list.get(i2).getA0449().equals("2")) {
                        list_zz.add(list.get(i2));
                    }
                }
                this.a01EducationService.getBaseMapper().deleteById(personid);
                A01Education a01Education = MeetData(list_qrz, list_zz);
                a01Education.setFlowid(personid);
                this.a01EducationService.save(a01Education);
                return;
            }
            return;
        }
        this.a01EducationService.removeById(personid);
    }

    public A01Education MeetData(List<A04> list_qrz, List<A04> list_zz) {
        String A0187 = "";
        String A0188 = "";
        String A0189 = "";
        String A0190 = "";
        String A0191 = "";
        String A0192 = "";
        if (list_qrz.size() == 1) {
            A04 a04 = list_qrz.get(0);
            if (a04.getA0405() != null) {
                A0187 = a04.getA0405();
            }
            if (a04.getA0435() != null) {
                A0188 = A0188 + a04.getA0435();
            }
            if (a04.getA0467() != null) {
                A0188 = A0188 + a04.getA0467();
            }
            if (a04.getA0411() != null) {
                A0188 = A0188 + a04.getA0411();
            }
            if (a04.getA0440() != null) {
                A0189 = a04.getA0440();
            }
        } else if (list_qrz.size() == 2) {
            A04 a04_1 = list_qrz.get(0);
            A04 a04_2 = list_qrz.get(1);
            if (a04_1.getA0405() != null) {
                A0187 = a04_1.getA0405();
                if (a04_2.getA0405() != null) {
                    A0187 = A0187 + "\n" + a04_2.getA0405();
                }
            }
            String shool1 = "";
            if (a04_1.getA0435() != null) {
                shool1 = shool1 + a04_1.getA0435();
            }
            if (a04_1.getA0467() != null) {
                shool1 = shool1 + a04_1.getA0467();
            }
            if (a04_1.getA0411() != null) {
                shool1 = shool1 + a04_1.getA0411();
            }
            String shool2 = "";
            if (a04_2.getA0435() != null) {
                shool2 = shool2 + a04_2.getA0435();
            }
            if (a04_2.getA0467() != null) {
                shool2 = shool2 + a04_2.getA0467();
            }
            if (a04_2.getA0411() != null) {
                shool2 = shool2 + a04_2.getA0411();
            }
            if (shool1.equals(shool2)) {
                A0188 = shool1;
            } else {
                A0188 = shool1 + "\n" + shool2;
            }
            if (a04_1.getA0440() != null) {
                A0189 = a04_1.getA0440();
                if (a04_2.getA0440() != null) {
                    A0189 = A0189 + "\n" + a04_2.getA0440();
                }
            }
        }
        if (list_zz.size() == 1) {
            A04 a042 = list_zz.get(0);
            if (a042.getA0405() != null) {
                A0190 = a042.getA0405();
            }
            if (a042.getA0435() != null) {
                A0191 = A0191 + a042.getA0435();
            }
            if (a042.getA0467() != null) {
                A0191 = A0191 + a042.getA0467();
            }
            if (a042.getA0411() != null) {
                A0191 = A0191 + a042.getA0411();
            }
            if (a042.getA0440() != null) {
                A0192 = a042.getA0440();
            }
        } else if (list_zz.size() == 2) {
            A04 a04_12 = list_zz.get(0);
            A04 a04_22 = list_zz.get(1);
            if (a04_12.getA0405() != null) {
                A0190 = a04_12.getA0405();
                if (a04_22.getA0405() != null) {
                    A0190 = A0190 + "\n" + a04_22.getA0405();
                }
            }
            String shool12 = "";
            if (a04_12.getA0435() != null) {
                shool12 = shool12 + a04_12.getA0435();
            }
            if (a04_12.getA0467() != null) {
                shool12 = shool12 + a04_12.getA0467();
            }
            if (a04_12.getA0411() != null) {
                shool12 = shool12 + a04_12.getA0411();
            }
            String shool22 = "";
            if (a04_22.getA0435() != null) {
                shool22 = shool22 + a04_22.getA0435();
            }
            if (a04_22.getA0467() != null) {
                shool22 = shool22 + a04_22.getA0467();
            }
            if (a04_22.getA0411() != null) {
                shool22 = shool22 + a04_22.getA0411();
            }
            if (shool12.equals(shool22)) {
                A0191 = shool12;
            } else {
                A0191 = shool12 + "\n" + shool22;
            }
            if (a04_12.getA0440() != null) {
                A0192 = a04_12.getA0440();
                if (a04_22.getA0440() != null) {
                    A0192 = A0192 + "\n" + a04_22.getA0440();
                }
            }
        }
        A01Education a01Education = new A01Education();
        a01Education.setA0187(A0187 == null ? "" : A0187);
        a01Education.setA0188(A0188 == null ? "" : A0188);
        a01Education.setA0189(A0189 == null ? "" : A0189);
        a01Education.setA0190(A0190 == null ? "" : A0190);
        a01Education.setA0191(A0191 == null ? "" : A0191);
        a01Education.setA0192(A0192 == null ? "" : A0192);
        return a01Education;
    }

    public void qrz(String personid) {
        String A0187 = "";
        String A0188 = "";
        String A0189 = "";
        String A0187r = "";
        String A0188r = "";
        String A0189r = "";
        Map<String, Object> map = new HashMap<>();
        map.put("personid", personid);
        map.put("A0449", "1");
        List<A04> list2 = this.a04Ser.selectByXL(map);
        if (list2.size() > 1) {
            for (int i = 0; i < list2.size(); i++) {
                if ((A0187 == null || A0187 == "") && list2.get(i).getA0405() != null) {
                    A0187 = list2.get(i).getA0405();
                    if (list2.get(i).getA0435() != null) {
                        A0188 = A0188 + list2.get(i).getA0435();
                    }
                    if (list2.get(i).getA0467() != null) {
                        A0188 = A0188 + list2.get(i).getA0467();
                    }
                    if (list2.get(i).getA0411() != null) {
                        A0188 = A0188 + list2.get(i).getA0411();
                    }
                    if (list2.get(i).getA0440() != null) {
                        A0189 = list2.get(i).getA0440();
                    }
                }
            }
            String xx1 = A0187 + A0188 + A0189;
            for (int i2 = 0; i2 < list2.size(); i2++) {
                if ((A0189r == null || A0189r == "") && list2.get(i2).getA0440() != null) {
                    A0189r = list2.get(i2).getA0440();
                    if (list2.get(i2).getA0435() != null) {
                        A0188r = A0188r + list2.get(i2).getA0435();
                    }
                    if (list2.get(i2).getA0467() != null) {
                        A0188r = A0188r + list2.get(i2).getA0467();
                    }
                    if (list2.get(i2).getA0411() != null) {
                        A0188r = A0188r + list2.get(i2).getA0411();
                    }
                    if (list2.get(i2).getA0405() != null) {
                        A0187r = list2.get(i2).getA0405();
                    }
                }
            }
            if (!(A0187r + A0188r + A0189r).equals(xx1)) {
                A0188 = A0188 + "\n" + A0188r;
                if (A0187 == null || A0187 == "") {
                    A0187 = A0187r;
                }
                if (A0189 == null || A0189 == "") {
                    A0189 = A0189r;
                }
            }
        } else if (list2.size() == 1) {
            if (list2.get(0).getA0405() != null) {
                A0187 = list2.get(0).getA0405();
            }
            if (list2.get(0).getA0435() != null) {
                A0188 = A0188 + list2.get(0).getA0435();
            }
            if (list2.get(0).getA0467() != null) {
                A0188 = A0188 + list2.get(0).getA0467();
            }
            if (list2.get(0).getA0411() != null) {
                A0188 = A0188 + list2.get(0).getA0411();
            }
            if (list2.get(0).getA0440() != null) {
                A0189 = list2.get(0).getA0440();
            }
        }
        A01 a01 = new A01();
        a01.setFlowid(personid);
        a01.setA0187(A0187);
        a01.setA0188(A0188);
        a01.setA0189(A0189);
        this.a01Service.updateById(a01);
    }

    public A01 zaiziEducation(String personid) {
        String A0190 = "";
        String A0191 = "";
        String A0192 = "";
        String A0191_1 = " ";
        String A0191_2 = "";
        A01 a01 = new A01();
        a01.setFlowid(personid);
        Map<String, Object> map = new HashMap<>();
        map.put("personid", personid);
        map.put("A0449", "2");
        List<A04> list = this.a04Ser.selectByXL(map);
        for (A04 a04 : list) {
            if (a04.getA0405() != null && !a04.getA0405().equals("") && A0190.equals("")) {
                A0190 = a04.getA0405();
                a01.setA0190(A0190);
                if (a04.getA0435() == null) {
                    A0191_1 = "";
                } else if ((a04.getA0435() + a04.getA0467()) == null) {
                    A0191_1 = "";
                } else {
                    A0191_1 = new StringBuilder().append(a04.getA0467()).append(a04.getA0411()).toString() == null ? "" : a04.getA0411();
                }
                A0191 = A0191_1.equals(A0191_2) ? A0191_1 : A0191_1 + "\n" + A0191_2;
                a01.setA0191(A0191.trim());
            }
            if (a04.getA0440() != null && !a04.getA0440().equals("") && A0192.equals("")) {
                A0192 = a04.getA0440();
                a01.setA0192(A0192);
                if (a04.getA0435() == null) {
                    A0191_2 = "";
                } else if ((a04.getA0435() + a04.getA0467()) == null) {
                    A0191_2 = "";
                } else {
                    A0191_2 = new StringBuilder().append(a04.getA0467()).append(a04.getA0411()).toString() == null ? "" : a04.getA0411();
                }
                A0191 = A0191_1.equals(A0191_2) ? A0191_1 : A0191_1 + "\n" + A0191_2;
                a01.setA0191(A0191.trim());
            }
            if (!(A0190 == "" || A0192 == "")) {
                return a01;
            }
        }
        List<A04> filterlist_1 = (List) list.stream().filter(s -> {
            return s.getA0440() != null && s.getA0405() == null;
        }).collect(Collectors.toList());
        if (filterlist_1.size() <= 1 || !filterlist_1.get(0).getA0463().substring(0, 1).equals(filterlist_1.get(1).getA0463().substring(0, 1))) {
            List<A04> filterlist_2 = (List) list.stream().filter(s -> {
                return s.getA0440() == null && s.getA0405() != null;
            }).collect(Collectors.toList());
            if (filterlist_2.size() <= 1 || !filterlist_2.get(0).getA0460().substring(0, 1).equals(filterlist_2.get(1).getA0460().substring(0, 1))) {
                a01.setA0190(A0190);
                a01.setA0191(A0191);
                a01.setA0192(A0192);
                return a01;
            }
            String A01902 = filterlist_2.get(0).getA0405();
            String A01912 = filterlist_2.get(0).getA0435() + filterlist_2.get(0).getA0467() + filterlist_2.get(0).getA0411() + "\n" + filterlist_2.get(1).getA0435() + filterlist_2.get(1).getA0467() + filterlist_2.get(1).getA0411();
            String A01922 = filterlist_2.get(1).getA0405();
            a01.setA0190(A01902);
            a01.setA0191(A01912);
            a01.setA0192(A01922);
            return a01;
        }
        String A01903 = filterlist_1.get(0).getA0440();
        String A01913 = filterlist_1.get(0).getA0435() + filterlist_1.get(0).getA0467() + filterlist_1.get(0).getA0411() + "\n" + filterlist_1.get(1).getA0435() + filterlist_1.get(1).getA0467() + filterlist_1.get(1).getA0411();
        String A01923 = filterlist_1.get(1).getA0440();
        a01.setA0190(A01903);
        a01.setA0191(A01913);
        a01.setA0192(A01923);
        return a01;
    }

    public void zz(String personid) {
        String A0190 = "";
        String A0191 = "";
        String A0192 = "";
        String A0190r = "";
        String A0191r = "";
        String A0192r = "";
        Map<String, Object> map = new HashMap<>();
        map.put("personid", personid);
        map.put("A0449", "2");
        List<A04> list2 = this.a04Ser.selectByXL(map);
        if (list2.size() > 0) {
            for (int i = 0; i < list2.size(); i++) {
                if ((A0190 == "" || A0190 == null) && list2.get(i).getA0405() != null) {
                    A0190 = list2.get(i).getA0405();
                    if (list2.get(i).getA0435() != null) {
                        A0191 = A0191 + list2.get(i).getA0435();
                    }
                    if (list2.get(i).getA0467() != null) {
                        A0191 = A0191 + list2.get(i).getA0467();
                    }
                    if (list2.get(i).getA0411() != null) {
                        A0191 = A0191 + list2.get(i).getA0411();
                    }
                    if (list2.get(i).getA0440() != null) {
                        A0192 = list2.get(i).getA0440();
                    }
                }
            }
            String xx1 = A0190 + A0191 + A0192;
            for (int i2 = 0; i2 < list2.size(); i2++) {
                if ((A0192r == null || A0192r == "") && list2.get(i2).getA0440() != null) {
                    A0192r = list2.get(i2).getA0440();
                    if (list2.get(i2).getA0435() != null) {
                        A0191r = A0191r + list2.get(i2).getA0435();
                    }
                    if (list2.get(i2).getA0467() != null) {
                        A0191r = A0191r + list2.get(i2).getA0467();
                    }
                    if (list2.get(i2).getA0411() != null) {
                        A0191r = A0191r + list2.get(i2).getA0411();
                    }
                    if (list2.get(i2).getA0405() != null) {
                        A0190r = list2.get(i2).getA0405();
                    }
                }
            }
            if (!(A0190r + A0191r + A0192r).equals(xx1)) {
                A0191 = A0191 + "\n" + A0191r;
                if (A0190 == null || A0190 == "") {
                    A0190 = A0190r;
                }
                if (!(A0192 == null || A0192 == "")) {
                    A0192 = A0192.toString();
                }
                if (!(A0192r == null || A0192r == "")) {
                    A0192 = A0192r.toString();
                }
            }
            if (A0190 == null || A0190 == "") {
                List<A04> boys = (List) list2.stream().filter(s -> {
                    return s.getA0440() != null && s.getA0405() == null;
                }).collect(Collectors.toList());
                if (boys.size() > 1) {
                    A0190 = boys.get(0).getA0440();
                    String A01912 = "";
                    A0192 = boys.get(1).getA0440();
                    if (boys.get(0).getA0435() != null) {
                        A01912 = A01912 + boys.get(0).getA0435();
                    }
                    if (boys.get(0).getA0467() != null) {
                        A01912 = A01912 + boys.get(0).getA0467();
                    }
                    if (boys.get(0).getA0411() != null) {
                        A01912 = A01912 + boys.get(0).getA0411();
                    }
                    A0191 = A01912 + "\n";
                    if (boys.get(1).getA0435() != null) {
                        A0191 = A0191 + boys.get(1).getA0435();
                    }
                    if (boys.get(1).getA0467() != null) {
                        A0191 = A0191 + boys.get(1).getA0467();
                    }
                    if (boys.get(1).getA0411() != null) {
                        A0191 = A0191 + boys.get(1).getA0411();
                    }
                }
            }
        }
        A01 a01 = new A01();
        a01.setFlowid(personid);
        a01.setA0190(A0190);
        a01.setA0191(A0191);
        a01.setA0192(A0192);
        this.a01Service.updateById(a01);
    }

    public void zz2(String personid) {
        String sc;
        String scw;
        String A0190 = "";
        String A0191 = "";
        String A0192 = "";
        Map<String, Object> map = new HashMap<>();
        map.put("personid", personid);
        map.put("A0449", "2");
        List<A04> list2 = this.a04Ser.selectByXL(map);
        if (list2.size() > 0) {
            if (list2.size() == 1) {
                if (list2.get(0).getA0405() != null) {
                    A0190 = list2.get(0).getA0405();
                }
                if (list2.get(0).getA0435() != null) {
                    A0191 = A0191 + list2.get(0).getA0435();
                }
                if (list2.get(0).getA0467() != null) {
                    A0191 = A0191 + list2.get(0).getA0467();
                }
                if (list2.get(0).getA0411() != null) {
                    A0191 = A0191 + list2.get(0).getA0411();
                }
                if (list2.get(0).getA0440() != null) {
                    A0192 = list2.get(0).getA0440();
                }
            }
            if (list2.size() > 1) {
                A04 a04_1 = list2.get(0);
                A04 a04_2 = list2.get(1);
                if (!(a04_1 == null || a04_2 == null)) {
                    String xx1 = a04_1.getA0405();
                    String xx2 = a04_2.getA0405();
                    if (xx1 == null || xx2 == null) {
                        if (xx1 != null) {
                            A0190 = a04_1.getA0405();
                        }
                        if (xx2 != null) {
                            A0190 = a04_2.getA0405();
                        }
                    } else if (a04_1.getA0405().equals(a04_2.getA0405())) {
                        A0190 = a04_1.getA0405();
                    } else {
                        A0190 = a04_1.getA0405() + "\n" + a04_2.getA0405();
                    }
                    if (a04_1.getA0440() == null || a04_2.getA0440() == null) {
                        if (a04_1.getA0440() != null) {
                            A0192 = a04_1.getA0440();
                        }
                        if (a04_2.getA0440() != null) {
                            A0192 = a04_2.getA0440();
                        }
                    } else if (a04_1.getA0440().equals(a04_2.getA0440())) {
                        A0192 = a04_1.getA0440();
                    } else {
                        A0192 = a04_1.getA0440() + "\n" + a04_2.getA0440();
                    }
                    String school1 = "";
                    String school2 = "";
                    if (a04_1.getA0435() != null) {
                        school1 = school1 + a04_1.getA0435();
                    }
                    if (a04_1.getA0467() != null) {
                        school1 = school1 + a04_1.getA0467();
                    }
                    if (a04_1.getA0411() != null) {
                        school1 = school1 + a04_1.getA0411();
                    }
                    if (a04_2.getA0435() != null) {
                        school2 = school2 + a04_2.getA0435();
                    }
                    if (a04_2.getA0467() != null) {
                        school2 = school2 + a04_2.getA0467();
                    }
                    if (a04_2.getA0411() != null) {
                        school2 = school2 + a04_2.getA0411();
                    }
                    String xl1 = a04_1.getA0460().substring(0, 1);
                    String xl2 = a04_2.getA0460().substring(0, 1);
                    if (!xl1.equals(xl2)) {
                        sc = school1;
                    } else if ("0".equals(xl1) && "0".equals(xl2)) {
                        sc = "";
                    } else if (school1.equals(school2)) {
                        sc = school1;
                    } else {
                        sc = school1 + "、" + school2;
                    }
                    String xw1 = a04_1.getA0463().substring(0, 1);
                    String xw2 = a04_2.getA0463().substring(0, 1);
                    if (!xw1.equals(xw2)) {
                        scw = school1;
                    } else if ("0".equals(xw1) && "0".equals(xw2)) {
                        scw = "";
                    } else if (school1.equals(school2)) {
                        scw = school1;
                    } else {
                        scw = school1 + "、" + school2;
                    }
                    if (sc.equals(scw)) {
                        A0191 = sc;
                    } else {
                        A0191 = sc + "\n" + scw;
                    }
                }
            }
        }
        A01 a01 = this.a01Service.selectByPrimaryKey(personid);
        a01.setA0190(A0190);
        a01.setA0191(A0191);
        a01.setA0192(A0192);
        this.a01Service.updateByPrimaryKeySelective(a01);
    }

    public void qrz2(String personid) {
        String A0187 = "";
        String A0188 = "";
        String A0189 = "";
        Map<String, Object> map = new HashMap<>();
        map.put("personid", personid);
        map.put("A0449", "1");
        List<A04> list2 = this.a04Ser.selectByXL(map);
        if (list2.size() > 0) {
            if (list2.size() == 1) {
                if (list2.get(0).getA0405() != null) {
                    A0187 = list2.get(0).getA0405();
                }
                if (list2.get(0).getA0435() != null) {
                    A0188 = A0188 + list2.get(0).getA0435();
                }
                if (list2.get(0).getA0467() != null) {
                    A0188 = A0188 + list2.get(0).getA0467();
                }
                if (list2.get(0).getA0411() != null) {
                    A0188 = A0188 + list2.get(0).getA0411();
                }
                if (list2.get(0).getA0440() != null) {
                    A0189 = list2.get(0).getA0440();
                }
            }
            if (list2.size() > 1) {
                A04 a04_1 = list2.get(0);
                A04 a04_2 = list2.get(1);
                if (!(a04_1 == null || a04_2 == null)) {
                    a04_1.getA0405();
                    a04_2.getA0405();
                    if (a04_1.getA0405().equals(a04_2.getA0405())) {
                        A0187 = a04_1.getA0405();
                    } else {
                        A0187 = a04_1.getA0405();
                    }
                    if (a04_1.getA0440().equals(a04_2.getA0440())) {
                        A0189 = a04_1.getA0440();
                    } else {
                        A0189 = a04_1.getA0440() + "\n" + a04_2.getA0440();
                    }
                    String school1 = a04_1.getA0435() + a04_1.getA0467() + a04_1.getA0411();
                    String school2 = a04_2.getA0435() + a04_2.getA0467() + a04_2.getA0411();
                    if (school1.equals(school2)) {
                        A0188 = school1;
                    } else {
                        A0188 = school1 + "\n" + school2;
                    }
                }
            }
        }
        A01 a01 = this.a01Service.selectByPrimaryKey(personid);
        a01.setA0187(A0187);
        a01.setA0188(A0188);
        a01.setA0189(A0189);
        this.a01Service.updateByPrimaryKeySelective(a01);
    }

    public void saveA01Msg(String personid) {
        qrz(personid);
        this.a01Service.updateById(zaiziEducation(personid));
    }

    @GetMapping({"/list/{personId}"})
    @ApiOperation("获取学历列表")
    public R list(@PathVariable String personId) {
        return R.ok().put("page", (Object) this.a04Ser.selectByxl(personId));
    }

    @GetMapping({"/info/{flowId}"})
    @ApiOperation("获取学历信息")
    public R info(@PathVariable("flowId") String flowId) {
        return R.ok().put("a04", (Object) ((A04) this.a04Ser.getBaseMapper().selectById(flowId)));
    }

    @PostMapping({"/save"})
    @A04Tag("更新")
    @SysLog(value = "新增学历信息", target = "A01", set = "A04", type = 0)
    @ApiOperation("添加学历")
    public R save(@RequestBody A04 a) {
        a.setFlowid(GenerateUUID.getUUID());
        this.a04Ser.save(a);
        updateA01s(a, "add");
        return R.ok();
    }

    @PostMapping({"/update"})
    @A04Tag("更新")
    @SysLog(value = "修改学历信息", target = "A01", set = "A04", type = 1)
    @ApiOperation("学历更新")
    public R update(@RequestBody A04 a) {
        ValidatorUtils.validateEntity(a, new Class[0]);
        this.a04Ser.getBaseMapper().updateById(a);
        updateA01s(a, "update");
        return R.ok();
    }

    @PostMapping({"/delete"})
    @A04Tag("删除")
    @SysLog(value = "删除学历信息", target = "A01", set = "A04", type = DateUtil.SUB_MONTH)
    @ApiOperation("学历删除")
    public R delete(@RequestBody String[] flowids) {
        this.a04Ser.getBaseMapper().deleteBatchIds(Arrays.asList(flowids));
        return R.ok();
    }

    @PostMapping({"/upOrder"})
    @ApiOperation("保存学历排序")
    public R upOrder(@RequestBody String[] flowids) {
        if (flowids.length == 0) {
            return R.error();
        }
        for (short i = 0; i < flowids.length; i = (short) (i + 1)) {
            A04 a04 = new A04();
            a04.setFlowid(flowids[i]);
            a04.setSerial(Short.valueOf(i));
            this.a04Ser.updateByPrimaryKeySelective(a04);
        }
        return R.ok();
    }

    @GetMapping({"/getA0460"})
    @ApiOperation("获取学历字典")
    public R getA0460() {
        Map<String, Object> map = new HashMap<>();
        map.put("tableName", "DIC_XUELI");
        return R.ok().put("data", (Object) this.dIC_ZBService.getAllForTree(map));
    }

    @GetMapping({"/getEducation"})
    @ApiOperation("获取快捷查询学历字典")
    public R getEducation() {
        LambdaQueryWrapper lambdaQueryWrapper = Wrappers.<A04>lambdaQuery().apply("DISTINCT a0405").isNotNull(A04::getA0405);
        return R.ok().put("data", (Object) this.a04Ser.getBaseMapper().selectObjs(lambdaQueryWrapper));
    }

    @GetMapping({"/getA0440"})
    @ApiOperation("获取学位字典")
    public R getA0440() {
        Map<String, Object> map = new HashMap<>();
        map.put("tableName", "DIC_GB6864");
        return R.ok().put("data", (Object) this.dIC_ZBService.getAllForTree(map));
    }

    @GetMapping({"/getA0410"})
    @ApiOperation("获取专业字典")
    public R getA0410() {
        Map<String, Object> map = new HashMap<>();
        map.put("tableName", "DIC_AI");
        return R.ok().put("data", (Object) this.dIC_ZBService.getAllForTree(map));
    }

    public void updateA01_3(List<A04> list, String personid) {
        A01 a01_qrz = new A01();
        A01 a01_zz = new A01();
        if (list.size() > 0) {
            List<A04> list_qrz = new ArrayList<>();
            List<A04> list_zz = new ArrayList<>();
            boolean boo = false;
            int i = 0;
            while (true) {
                if (i >= list.size()) {
                    break;
                } else if (list.get(i).getIsout().shortValue() != 9) {
                    boo = false;
                    break;
                } else {
                    boo = true;
                    i++;
                }
            }
            if (!boo) {
                for (int i2 = 0; i2 < list.size(); i2++) {
                    if (list.get(i2).getIsout().shortValue() == 1 && list.get(i2).getA0449().equals("1")) {
                        list_qrz.add(list.get(i2));
                    } else if (list.get(i2).getIsout().shortValue() == 1 && list.get(i2).getA0449().equals("2")) {
                        list_zz.add(list.get(i2));
                    }
                }
                if (list_qrz.size() == 1) {
                    a01_qrz = getlist_qrz(list_qrz.get(0));
                } else if (list_qrz.size() == 2) {
                    a01_qrz = getlist_qrz_2(list_qrz.get(0), list_qrz.get(1));
                }
                if (list_zz.size() == 1) {
                    a01_zz = getlist_zz(list_zz.get(0));
                } else if (list_zz.size() == 2) {
                    a01_zz = getlist_zz_2(list_zz.get(0), list_zz.get(1));
                }
                A01 a01 = new A01();
                a01.setFlowid(personid);
                a01.setA0187(a01_qrz.getA0187() == null ? "" : a01_qrz.getA0187());
                a01.setA0188(a01_qrz.getA0188() == null ? "" : a01_qrz.getA0188());
                a01.setA0189(a01_qrz.getA0189() == null ? "" : a01_qrz.getA0189());
                a01.setA0190(a01_zz.getA0190() == null ? "" : a01_zz.getA0190());
                a01.setA0191(a01_zz.getA0191() == null ? "" : a01_zz.getA0191());
                a01.setA0192(a01_zz.getA0192() == null ? "" : a01_zz.getA0192());
                this.a01Service.updateById(a01);
            }
        }
    }

    @PostMapping({"/updateA01_2/{personid}"})
    @Transactional
    @ApiOperation("更新A01表")
    public R updateA01_2(@RequestBody List<A04> list, @PathVariable("personid") String personid) {
        A01 a01_qrz = new A01();
        A01 a01_zz = new A01();
        if (list.size() <= 0) {
            return R.error();
        }
        List<A04> list_qrz = new ArrayList<>();
        List<A04> list_zz = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getIsout().shortValue() == 1 && list.get(i).getA0449().equals("1")) {
                list_qrz.add(list.get(i));
            } else if (list.get(i).getIsout().shortValue() == 1 && list.get(i).getA0449().equals("2")) {
                list_zz.add(list.get(i));
            }
        }
        if (list_qrz.size() == 1) {
            a01_qrz = getlist_qrz(list_qrz.get(0));
        } else if (list_qrz.size() == 2) {
            a01_qrz = getlist_qrz_2(list_qrz.get(0), list_qrz.get(1));
        }
        if (list_zz.size() == 1) {
            a01_zz = getlist_zz(list_zz.get(0));
        } else if (list_zz.size() == 2) {
            a01_zz = getlist_zz_2(list_zz.get(0), list_zz.get(1));
        }
        A01 a01 = new A01();
        a01.setFlowid(personid);
        a01.setA0187(a01_qrz.getA0187() == null ? "" : a01_qrz.getA0187());
        a01.setA0188(a01_qrz.getA0188() == null ? "" : a01_qrz.getA0188());
        a01.setA0189(a01_qrz.getA0189() == null ? "" : a01_qrz.getA0189());
        a01.setA0190(a01_zz.getA0190() == null ? "" : a01_zz.getA0190());
        a01.setA0191(a01_zz.getA0191() == null ? "" : a01_zz.getA0191());
        a01.setA0192(a01_zz.getA0192() == null ? "" : a01_zz.getA0192());
        this.a01Service.updateById(a01);
        return R.ok();
    }

    public A01 getlist_zz_2(A04 a04_1, A04 a04_2) {
        String A0191;
        String A0190 = "";
        String A0192 = "";
        if (a04_1.getA0405() != null && a04_1.getA0440() != null && a04_1.getA0405() != "" && a04_1.getA0440() != "") {
            A0190 = a04_1.getA0405();
            if (!(a04_1.getA0440() == null || a04_1.getA0440() == "")) {
                A0190 = A0190 + "，" + a04_1.getA0440();
            }
        } else if (a04_1.getA0405() != null && a04_1.getA0405() != "") {
            A0190 = a04_1.getA0405();
        } else if (!(a04_1.getA0440() == null || a04_1.getA0440() == "")) {
            A0190 = a04_1.getA0440();
        }
        String shool1 = "";
        if (a04_1.getA0435() != null) {
            shool1 = shool1 + a04_1.getA0435();
        }
        if (a04_1.getA0467() != null) {
            shool1 = shool1 + a04_1.getA0467();
        }
        if (a04_1.getA0411() != null) {
            shool1 = shool1 + a04_1.getA0411();
        }
        if (a04_2.getA0405() != null && a04_2.getA0440() != null && a04_2.getA0405() != "" && a04_2.getA0440() != "") {
            A0192 = a04_2.getA0405();
            if (!(a04_2.getA0440() == null || a04_2.getA0440() == "")) {
                A0192 = A0192 + "，" + a04_2.getA0440();
            }
        } else if (a04_2.getA0405() != null && a04_2.getA0405() != "") {
            A0192 = a04_2.getA0405();
        } else if (!(a04_2.getA0440() == null || a04_2.getA0440() == "")) {
            A0192 = a04_2.getA0440();
        }
        String shool2 = "";
        if (a04_2.getA0435() != null) {
            shool2 = shool2 + a04_2.getA0435();
        }
        if (a04_2.getA0467() != null) {
            shool2 = shool2 + a04_2.getA0467();
        }
        if (a04_2.getA0411() != null) {
            shool2 = shool2 + a04_2.getA0411();
        }
        if (shool2.equals(shool1)) {
            A0191 = shool1;
        } else {
            A0191 = shool1 + "\n" + shool2;
        }
        A01 a01 = new A01();
        a01.setA0190(A0190);
        a01.setA0191(A0191);
        a01.setA0192(A0192);
        return a01;
    }

    public A01 getlist_qrz_2(A04 a04_1, A04 a04_2) {
        String A0188;
        String A0187 = "";
        String A0189 = "";
        if (a04_1.getA0405() != null && a04_1.getA0440() != null && a04_1.getA0405() != "" && a04_1.getA0440() != "") {
            A0187 = a04_1.getA0405();
            if (!(a04_1.getA0440() == null || a04_1.getA0440() == "")) {
                A0187 = A0187 + "，" + a04_1.getA0440();
            }
        } else if (a04_1.getA0405() != null && a04_1.getA0405() != "") {
            A0187 = a04_1.getA0405();
        } else if (!(a04_1.getA0440() == null || a04_1.getA0440() == "")) {
            A0187 = a04_1.getA0440();
        }
        String shool1 = "";
        if (a04_1.getA0435() != null) {
            shool1 = shool1 + a04_1.getA0435();
        }
        if (a04_1.getA0467() != null) {
            shool1 = shool1 + a04_1.getA0467();
        }
        if (a04_1.getA0411() != null) {
            shool1 = shool1 + a04_1.getA0411();
        }
        if (a04_2.getA0405() != null && a04_2.getA0440() != null && a04_2.getA0405() != "" && a04_2.getA0440() != "") {
            A0189 = a04_2.getA0405();
            if (!(a04_2.getA0440() == null || a04_2.getA0440() == "")) {
                A0189 = A0189 + "，" + a04_2.getA0440();
            }
        } else if (a04_2.getA0405() != null && a04_2.getA0405() != "") {
            A0189 = a04_2.getA0405();
        } else if (!(a04_2.getA0440() == null || a04_2.getA0440() == "")) {
            A0189 = a04_2.getA0440();
        }
        String shool2 = "";
        if (a04_2.getA0435() != null) {
            shool2 = shool2 + a04_2.getA0435();
        }
        if (a04_2.getA0467() != null) {
            shool2 = shool2 + a04_2.getA0467();
        }
        if (a04_2.getA0411() != null) {
            shool2 = shool2 + a04_2.getA0411();
        }
        if (shool2.equals(shool1)) {
            A0188 = shool1;
        } else {
            A0188 = shool1 + "\n" + shool2;
        }
        A01 a01 = new A01();
        a01.setA0187(A0187);
        a01.setA0188(A0188);
        a01.setA0189(A0189);
        return a01;
    }

    public A01 getlist_zz(A04 a04) {
        String A0190 = "";
        String A0191 = "";
        String A0192 = "";
        if (a04.getA0405() != null) {
            A0190 = a04.getA0405();
        }
        if (a04.getA0435() != null) {
            A0191 = A0191 + a04.getA0435();
        }
        if (a04.getA0467() != null) {
            A0191 = A0191 + a04.getA0467();
        }
        if (a04.getA0411() != null) {
            A0191 = A0191 + a04.getA0411();
        }
        if (a04.getA0440() != null) {
            A0192 = a04.getA0440();
        }
        A01 a01 = new A01();
        a01.setA0190(A0190);
        a01.setA0191(A0191);
        a01.setA0192(A0192);
        return a01;
    }

    public A01 getlist_qrz(A04 a04) {
        String A0187 = "";
        String A0188 = "";
        String A0189 = "";
        if (a04.getA0405() != null) {
            A0187 = a04.getA0405();
        }
        if (a04.getA0435() != null) {
            A0188 = A0188 + a04.getA0435();
        }
        if (a04.getA0467() != null) {
            A0188 = A0188 + a04.getA0467();
        }
        if (a04.getA0411() != null) {
            A0188 = A0188 + a04.getA0411();
        }
        if (a04.getA0440() != null) {
            A0189 = a04.getA0440();
        }
        A01 a01 = new A01();
        a01.setA0187(A0187);
        a01.setA0188(A0188);
        a01.setA0189(A0189);
        return a01;
    }

    public void qrz_2(A04 a04) {
        if (a04 != null) {
        }
    }

    public void zz_2(A04 a04) {
        if (a04 != null) {
        }
    }

    @GetMapping({"/updateAllA01info"})
    public R updateAllA01() {
        List<A01> a01List = this.a01Service.selectList(new HashMap<>());
        for (int n = 0; n < a01List.size(); n++) {
            try {
                List<A04> a04List = this.a04Ser.selectByxl(a01List.get(n).getFlowid());
                if (!CollectionUtils.isEmpty(a04List)) {
                }
                updateA01_3(a04List, a01List.get(n).getFlowid());
            } catch (Exception e) {
            }
        }
        return R.ok();
    }

    @PostMapping({"/updateA01/{personid}"})
    @Transactional
    @ApiOperation("更新A01")
    public R updateA01(@RequestBody A04[] a04, @PathVariable String personid) {
        String A0188;
        String A0191;
        String A0187 = "";
        String A0189 = "";
        String A0190 = "";
        String A0192 = "";
        String A01882 = "";
        String A01912 = "";
        for (A04 a042 : a04) {
            this.a04Ser.updateByPrimaryKeySelective(a042);
        }
        for (A04 a043 : a04) {
            A04 a = (A04) this.a04Ser.getBaseMapper().selectById(a043.getFlowid());
            if (!(a.getA0405() == null || a.getA0405() == "")) {
                if (a.getA0449().equals("1")) {
                    A0187 = A0187 + (a.getA0405() == null ? "" : a.getA0405() + ',');
                    String A01883 = ((A01882 + (a.getA0435() == null ? "" : a.getA0435())) + (a.getA0467() == null ? "" : a.getA0467())) + (a.getA0411() == null ? "" : a.getA0411());
                    A01882 = A01883 + (A01883.length() > 0 ? "," : "");
                } else {
                    A0190 = A0190 + (a.getA0405() == null ? "" : a.getA0405() + ',');
                    String A01913 = ((A01912 + (a.getA0435() == null ? "" : a.getA0435())) + (a.getA0467() == null ? "" : a.getA0467())) + (a.getA0411() == null ? "" : a.getA0411());
                    A01912 = A01913 + (A01913.length() > 0 ? "," : "");
                }
            }
        }
        if (A01882.length() > 0) {
            A01882 = A01882.substring(0, A01882.length() - 1);
        }
        if (A01912.length() > 0) {
            A01912 = A01912.substring(0, A01912.length() - 1);
        }
        String A01884 = A01882 + " ";
        String A01914 = A01912 + " ";
        String A0188_temp = "";
        String A0191_temp = "";
        for (A04 a044 : a04) {
            A04 a1 = (A04) this.a04Ser.getBaseMapper().selectById(a044.getFlowid());
            if (!(a1.getA0440() == null || a1.getA0440() == "")) {
                if (a1.getA0449().equals("1")) {
                    A0189 = A0189 + (a1.getA0440() == null ? "" : a1.getA0440() + ',');
                    String A0188_temp2 = ((A0188_temp + (a1.getA0435() == null ? "" : a1.getA0435())) + (a1.getA0467() == null ? "" : a1.getA0467())) + (a1.getA0411() == null ? "" : a1.getA0411());
                    A0188_temp = A0188_temp2 + (A0188_temp2.length() > 0 ? "," : "");
                } else {
                    A0192 = A0192 + (a1.getA0440() == null ? "" : a1.getA0440() + ',');
                    String A0191_temp2 = ((A0191_temp + (a1.getA0435() == null ? "" : a1.getA0435())) + (a1.getA0467() == null ? "" : a1.getA0467())) + (a1.getA0411() == null ? "" : a1.getA0411());
                    A0191_temp = A0191_temp2 + (A0191_temp2.length() > 0 ? "," : "");
                }
            }
        }
        if (A0188_temp.length() > 0) {
            A0188_temp = A0188_temp.substring(0, A0188_temp.length() - 1);
        }
        if (A0191_temp.length() > 0) {
            A0191_temp = A0191_temp.substring(0, A0191_temp.length() - 1);
        }
        if (A01884 == null || !A01884.trim().equals(A0188_temp)) {
            A0188 = A01884 + A0188_temp;
        } else {
            A0188 = A01884.trim();
        }
        if (A01914 == null || !A01914.trim().equals(A0191_temp)) {
            A0191 = A01914 + A0191_temp;
        } else {
            A0191 = A01914.trim();
        }
        A01 a01 = (A01) this.a01Service.getBaseMapper().selectById(personid);
        a01.setA0187(A0187.length() > 0 ? A0187.substring(0, A0187.length() - 1) : "");
        a01.setA0188(A0188.length() > 0 ? A0188 : "");
        a01.setA0189(A0189.length() > 0 ? A0189.substring(0, A0189.length() - 1) : "");
        a01.setA0190(A0190.length() > 0 ? A0190.substring(0, A0190.length() - 1) : "");
        a01.setA0191(A0191.length() > 0 ? A0191 : "");
        a01.setA0192(A0192.length() > 0 ? A0192.substring(0, A0192.length() - 1) : "");
        this.a01Service.updateByPrimaryKeySelective(a01);
        return R.ok("操作成功!");
    }

    public void updateA01s(A04 a04, String type) {
        String A0187 = "";
        String A0189 = "";
        String A0190 = "";
        String A0192 = "";
        String A0188 = "";
        String A0191 = "";
        if (a04 != null) {
            a04.setIsout((short) 1);
            this.a04Ser.updateById(a04);
            LambdaQueryWrapper<A04> lambdaQueryWrapper = new LambdaQueryWrapper();
            lambdaQueryWrapper.eq(A04::getPersonid, a04.getPersonid());
            List<A04> listA04 = this.a04Ser.getBaseMapper().selectList(lambdaQueryWrapper);
            if (listA04.size() != 0) {
                for (int i = 0; i < listA04.size(); i++) {
                    A04 a1 = (A04) this.a04Ser.getBaseMapper().selectById(listA04.get(i).getFlowid());
                    if (!(a1.getA0405() == null || a1.getA0405() == "")) {
                        if (a1.getA0449().equals("1")) {
                            A0187 = A0187 + (a1.getA0405() == null ? "" : a1.getA0405() + ',');
                            String A01882 = ((A0188 + (a1.getA0435() == null ? "" : a1.getA0435())) + (a1.getA0467() == null ? "" : a1.getA0467())) + (a1.getA0411() == null ? "" : "\n" + a1.getA0411());
                            A0188 = A01882 + (A01882.length() > 0 ? "," : "");
                        } else {
                            A0190 = A0190 + (a1.getA0405() == null ? "" : a1.getA0405() + ',');
                            String A01912 = ((A0191 + (a1.getA0435() == null ? "" : a1.getA0435())) + (a1.getA0467() == null ? "" : a1.getA0467())) + (a1.getA0411() == null ? "" : "\n" + a1.getA0411());
                            A0191 = A01912 + (A01912.length() > 0 ? "," : "");
                        }
                    }
                }
                if (A0188.length() > 0) {
                    A0188 = A0188.substring(0, A0188.length() - 1);
                }
                if (A0191.length() > 0) {
                    A0191 = A0191.substring(0, A0191.length() - 1);
                }
                String A01883 = A0188 + " ";
                String A01913 = A0191 + " ";
                String A0188_temp = "";
                String A0191_temp = "";
                for (int i2 = 0; i2 < listA04.size(); i2++) {
                    A04 a12 = (A04) this.a04Ser.getBaseMapper().selectById(listA04.get(i2).getFlowid());
                    if (!(a12.getA0440() == null || a12.getA0440() == "")) {
                        if (a12.getA0449().equals("1")) {
                            A0189 = A0189 + (a12.getA0440() == null ? "" : a12.getA0440() + ',');
                            String A0188_temp2 = ((A0188_temp + (a12.getA0435() == null ? "" : a12.getA0435())) + (a12.getA0467() == null ? "" : a12.getA0467())) + (a12.getA0411() == null ? "" : "\n" + a12.getA0411());
                            A0188_temp = A0188_temp2 + (A0188_temp2.length() > 0 ? "," : "");
                        } else {
                            A0192 = A0192 + (a12.getA0440() == null ? "" : a12.getA0440() + ',');
                            String A0191_temp2 = ((A0191_temp + (a12.getA0435() == null ? "" : a12.getA0435())) + (a12.getA0467() == null ? "" : a12.getA0467())) + (a12.getA0411() == null ? "" : "\n" + a12.getA0411());
                            A0191_temp = A0191_temp2 + (A0191_temp2.length() > 0 ? "," : "");
                        }
                    }
                }
                if (A0188_temp.length() > 0) {
                    A0188_temp = A0188_temp.substring(0, A0188_temp.length() - 1);
                }
                if (A0191_temp.length() > 0) {
                    A0191_temp = A0191_temp.substring(0, A0191_temp.length() - 1);
                }
                if (A01883 == null || !A01883.trim().equals(A0188_temp)) {
                    A0188 = A01883 + A0188_temp;
                } else {
                    A0188 = A01883.trim();
                }
                A0191 = (A01913 == null || !A01913.trim().equals(A0191_temp)) ? A01913 + A0191_temp : A01913.trim();
            }
        }
        A01 a01 = (A01) this.a01Service.getBaseMapper().selectById(a04.getPersonid());
        a01.setA0187(A0187.length() > 0 ? A0187.substring(0, A0187.length() - 1) : "");
        a01.setA0188(A0188.length() > 0 ? A0188 : "");
        a01.setA0189(A0189.length() > 0 ? A0189.substring(0, A0189.length() - 1) : "");
        a01.setA0190(A0190.length() > 0 ? A0190.substring(0, A0190.length() - 1) : "");
        a01.setA0191(A0191.length() > 0 ? A0191 : "");
        a01.setA0192(A0192.length() > 0 ? A0192.substring(0, A0192.length() - 1) : "");
        this.a01Service.updateByPrimaryKeySelective(a01);
    }
}
